//
//  MyAccountView2.m
//  iFlower
//
//  Created by khanh nguyen on 7/20/10.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "MyAccountView2.h"


@implementation MyAccountView2
@synthesize picker;
@synthesize theday;
@synthesize themonth;
@synthesize theyear;

-(IBAction)buttonMenu:(id)sender
{
	[self.navigationController popToRootViewControllerAnimated:YES];
}
/*
-(IBAction)test:(id)sender
{
	NSString * themessage = [NSString stringWithFormat:@"%@ -- %@ -- %@",
							[themonth objectAtIndex:[picker selectedRowInComponent:0]],
							[theday objectAtIndex:[picker selectedRowInComponent:1]],
							[theyear objectAtIndex:[picker selectedRowInComponent:2]]];
	NSLog(themessage);
}*/

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
	
	picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
	CGSize pickerSize = [picker sizeThatFits:CGSizeZero];
	picker.frame = CGRectMake(40,235,240,pickerSize.height - 50);
	picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
	//[picker setDelegate:self];
	picker.delegate = self;
	picker.dataSource = self;
	picker.showsSelectionIndicator = YES;
	
	[self.view addSubview:picker];
	
	
	
	//------------------
	NSArray *firstArray = [[NSArray alloc] initWithObjects:
	@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30",@"31",nil];
	self.theday = firstArray;
	[firstArray release];
	
	NSArray *secondArray = [[NSArray alloc] initWithObjects:
	@"January",@"February",@"March",@"April",@"May",@"June",@"July",@"August",@"September",@"October",@"November",@"December",nil];
	self.themonth = secondArray;
	[secondArray release];
	
	NSArray *thirdArray = [[NSArray alloc] initWithObjects:
	@"2002",@"2003",@"2004",@"2005",@"2006",@"2007",@"2008",@"2009",@"2010", @"2011", @"2012", @"2013", @"2014", @"2015", @"2016", @"2017", @"2018", @"2019", @"2020",nil];
	self.theyear = thirdArray;
	[thirdArray release];
	
	[super viewDidLoad];

/*	
	picker = [[UIPickerView alloc] initWithFrame:CGRectZero];
	CGSize pickerSize = [picker sizeThatFits:CGSizeZero];
	picker.frame = CGRectMake(40,235,240,pickerSize.height - 50);
	
	//picker.autoresizingMask = UIViewAutoresizingFlexibleWidth;
	[self.view addSubview:picker];
	
	[super viewDidLoad];
*/	

}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
	return 3;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view 
{
	UILabel *pickerLabel = (UILabel *)view;
	if ((pickerLabel == nil) || ([pickerLabel class] != [UILabel class])) 
	{ 
		CGRect frame = CGRectMake(0.0, 0.0, 100, 32);
		pickerLabel = [[[UILabel alloc] initWithFrame:frame] autorelease];
		pickerLabel.textAlignment = UITextAlignmentCenter;
		pickerLabel.backgroundColor = [UIColor clearColor];
		//pickerLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:15];
		pickerLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
	}			
	pickerLabel.textColor = [UIColor blackColor];
	NSString*  text = nil;
	if (component == 0) 
	{
		text = [self.themonth objectAtIndex:row];
	}
	else
		if (component == 1) 
		{
			text =  [self.theday objectAtIndex:row];
		}
		else 
		{
			text =  [self.theyear objectAtIndex:row];
		}
	
	pickerLabel.text = text;
	
	return pickerLabel;	
	
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
	if (component == 0) 
	{
		return [self.themonth count];
	}
	
	if (component == 1) 
	{
		return [self.theday count];
	}
	
	else 
	{
		return [self.theyear count];
	}
}

-(NSString *)pickerView:(UIPickerView *)pickerView
			titleForRow:(NSInteger)row forComponent:(NSInteger)component 
{
	if (component == 0) 
	{
		return [self.themonth objectAtIndex:row];
	}
	
	if (component == 1) 
	{
		return [self.theday objectAtIndex:row];
	}
	
	else 
	{
		return [self.theyear objectAtIndex:row];
	}
}
-(CGFloat)pickerView:(UIPickerView *)pickerView
   widthForComponent:(NSInteger)component {
	if (component == 0)
		return 110;
	else if (component == 1)
		return 45;
	return 55;
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	[picker release];
	[theday release];
	[themonth release];
	[theyear release];
    [super dealloc];
}


@end
